package com.hooya.fa.eu.biz.controller;

import com.hooya.fa.eu.api.vo.DictVO;
import com.hooya.fa.eu.biz.service.DictRelationService;
import com.hooya.integrated.common.core.util.R;
import com.hooya.integrated.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @Description 字典
 * @Author : Zongz
 * @Copyright Copyright (c) 豪雅集团
 * @Create 2024/5/16
 * @Version 1.0.0
 */
@Validated
@RestController
@RequiredArgsConstructor
@Tag(name = "字典")
@RequestMapping("/dict")
public class DictController {

    private final DictRelationService dictRelationService;

    @PostMapping("/add")
    @Inner(value = false)
    @Operation(summary = "字典新增【√】", description = "字典新增")
    public R add(@RequestBody @Valid DictVO dict) {
        dictRelationService.add(dict);
        return R.ok();
    }

    @GetMapping("/get")
    @Inner(value = false)
    @Operation(summary = "获取所有字典仓库列表【√】", description = "获取所有字典仓库列表")
    public R<List<DictVO>> getList() {
        return R.ok(dictRelationService.getCkDictList());
    }

    @PutMapping("/edit")
    @Inner(value = false)
    @Operation(summary = "字典编辑【√】", description = "字典编辑")
    public R edit(@RequestBody @Valid DictVO dict) {
        dictRelationService.edit(dict);
        return R.ok();
    }

    @DeleteMapping("/delete/{id}")
    @Inner(value = false)
    @Operation(summary = "字典删除【√】", description = "字典删除")
    public R delete(@PathVariable("id") Integer id, @RequestParam("name") @NotBlank String name) {
        dictRelationService.delete(id, name);
        return R.ok();
    }
}
